package com.inossem.warehousestorage_inossem.adapter.inStorage.chuangyou;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.inossem.warehousestorage_inossem.R;
import com.inossem.warehousestorage_inossem.activity.in_storage.chuangyou.CYInStorageSerialNumberActivity;
import com.inossem.warehousestorage_inossem.bean.outStorage.SNBean;
import com.inossem.warehousestorage_inossem.bean.outStorage.SNItemInfo;
import com.inossem.warehousestorage_inossem.dialog.DialogUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * TODO
 *
 * @author 王斯宇
 * @time on 2018/3/23 14:13
 * @email siyu.wang@inossem.com
 */
public class CYCInStorageSerialNumberAdapter extends BaseAdapter {

    private Context mContext;
    private LayoutInflater inflater;
    private List<SNItemInfo> list;
    private CYInStorageSerialNumberActivity.CYInStorageSerialNumberListener listener;

    public CYCInStorageSerialNumberAdapter(Context context  , List<SNItemInfo> list , CYInStorageSerialNumberActivity.CYInStorageSerialNumberListener listener) {
        this.mContext = context;
        inflater = LayoutInflater.from(context);
        this.list = list;
        this.listener = listener;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (convertView == null || (convertView != null && convertView.getTag() == null)) {
            convertView = inflater.inflate(R.layout.cy_view_change_storage_package_code, null);
            viewHolder = new ViewHolder();
            //初始化控件
            initView(viewHolder, convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        SNItemInfo bean = list.get(position);
        //初始化数据
        initData(mContext, viewHolder, convertView , bean);
        return convertView;
    }
    private void initView(ViewHolder viewHolder, View view) {
        viewHolder.name = (TextView) view.findViewById(R.id.name);
        viewHolder.code = (TextView) view.findViewById(R.id.code);
        viewHolder.imageView = (ImageView) view.findViewById(R.id.image);

    }
    private void initData(Context context,ViewHolder viewHolder, View view , SNItemInfo bean) {

        viewHolder.name.setText("序列号");
        viewHolder.code.setText(bean.getCode());
        viewHolder.code.setTextColor(mContext.getResources().getColor(R.color.common_font_item_name));
        viewHolder.imageView.setBackgroundResource(R.drawable.ico_arrow3_down);

        view.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                DialogUtils.getConfirmDialog(context, "是否删除？", new DialogUtils.ConfirmDialogListener() {
                    @Override
                    public void onConfirm(Dialog dialog) {
                        dialog.dismiss();
                        listener.onDeleteClickListener(bean.getType() , bean.getCode());
                    }
                }).show();

//                mChangeStorageMaterielListener.deleteMaterielItem(materielItem.getMat_id() ,materielItem.getLocation_id() , materielItem.getStock_position_id() , materielItem.getBatch(), materielItem.getMat_code());
                return true;
            }
        });

    }
    public class ViewHolder {
        private TextView name , code ;
        private ImageView imageView;
    }
}
